﻿using NAnt.Core.Attributes;
using NAnt.SVN.Attributes;
using NAnt.SVN.Util;
using System;

namespace NAnt.SVN.Tasks
{
    /// <summary>
    /// Implementation of a tag command, based on copy.
    /// You can run this tasc with the svntag tag in NAnt.
    /// $Id$
    /// </summary>
    [TaskName("svntag")]
    public sealed class Tag : Copy
    {
        #region Private Fields

        string tagname = "";

        #endregion

        #region Public Fields

        /// <summary>
        /// The source url
        /// </summary>
        [TaskAttribute("source", Required = true)]
        [TrunkUriValidator()]
        public override string Source
        {
            get { return base.Source; }
            set { base.Source = value; }
        }

        /// <summary>
        /// The destination url
        /// </summary>
        public override string Destination
        {
            get
            {
                Uri output = null;
                bool result = UrlUtil.ConvertTrunkToTags(new Uri(Source), out output);
                if (result) return output.AbsoluteUri + "/" + TagName;
                else return string.Empty;
            }
        }

        /// <summary>
        /// The name of the tag
        /// </summary>
        [TaskAttribute("tagname",Required=true)]
        [StringValidator(AllowEmpty=false)]
        public string TagName
        {
            get { return tagname; }
            set{ tagname = value; }
        }

        #endregion
    }
}
